package com.zmzncs.lmtc.module.customer.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zmzncs.lmtc.common.pojo.PageInfo;
import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.util.JsonUtil;
import com.zmzncs.lmtc.common.util.RestUtil;
import com.zmzncs.lmtc.module.customer.pojo.card_record.*;
import com.zmzncs.lmtc.module.customer.pojo.customer.CustomerDTO;
import com.zmzncs.lmtc.module.customer.pojo.customer.CustomerTableVO;
import com.zmzncs.lmtc.module.customer.service.CardRecordService;
import com.zmzncs.lmtc.module.promotion.pojo.duration_rule.DurationRuleTableVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 客户-车辆服务实时状态购买记录 前端控制器
 * </p>
 *
 * @author 任建波
 * @since 2020-10-12
 */
@Api(tags = "会员服务购买记录")
@RestController
@RequestMapping("/customer/card-record")
public class CardRecordController {

    @Autowired
    private CardRecordService cardRecordService;

    @ApiOperation(value = "优惠券使用记录")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name="pageNum", value="页码", required = true),
            @ApiImplicitParam(paramType="query", name="pageSize", value="页长", required = true),
            @ApiImplicitParam(paramType="query", name="ticketId", value="优惠券Id"),
    })
    @GetMapping(value = "getCardRecordList")
    public Rest<IPage<DurationRuleTableVO>> getCardRecordList(@NotNull Integer pageNum, @NotNull Integer pageSize, @NotNull Long ticketId) {
        IPage<CardRecordDTO> recordDTOIPage = cardRecordService.getCardRecordList(new Page<>(pageNum, pageSize), ticketId);
        PageInfo<CardRecordTableVO> page = JsonUtil.pageTransform(recordDTOIPage, CardRecordTableVO.class);

        return RestUtil.success(page);
    }


    @ApiOperation(value = "停车场在用月租卡信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name="pageNum", value="页码", required = true),
            @ApiImplicitParam(paramType="query", name="pageSize", value="页长", required = true),
            @ApiImplicitParam(paramType="query", name="parkId", value="停车场Id", required = true),
    })
    @GetMapping(value = "getUsingCardRecordByParkId")
    public Rest<IPage<ParkCardRecordVO>> getUsingCardRecordByParkId(@NotNull Integer pageNum, @NotNull Integer pageSize, @NotNull Long parkId) {
        IPage<CardRecordDTO> recordDTOIPage = cardRecordService.getUsingCardRecordByParkId(new Page<>(pageNum, pageSize), parkId);
        PageInfo<ParkCardRecordVO> page = JsonUtil.pageTransform(recordDTOIPage, ParkCardRecordVO.class);

        return RestUtil.success(page);
    }

    @ApiOperation(value = "停车场所有月租卡信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name="pageNum", value="页码", required = true),
            @ApiImplicitParam(paramType="query", name="pageSize", value="页长", required = true),
            @ApiImplicitParam(paramType="query", name="parkId", value="停车场Id", required = true),
    })
    @GetMapping(value = "getAllCardRecordByParkId")
    public Rest<IPage<ParkMontCardRecordVO>> getAllCardRecordByParkId(@NotNull Integer pageNum, @NotNull Integer pageSize, @NotNull Long parkId) {
        IPage<ParkMontCardRecordDTO> recordDTOIPage = cardRecordService.getAllCardRecordByParkId(pageNum,pageSize, parkId);
        PageInfo<ParkMontCardRecordDTO> page = JsonUtil.pageTransform(recordDTOIPage, ParkMontCardRecordDTO.class);

        return RestUtil.success(page);
    }




    @ApiOperation(value = "查询用户开通会员记录信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true)
    })
    @GetMapping(value = "/getCustomerVipRecordPage")
    public Rest<PageInfo<CustomerTableVO>> getCustomerVipRecordPage(@NotNull Integer pageNum, @NotNull Integer pageSize, @NotNull Long customerId) {
        IPage<CardRecordDTO> recordDTOIPage = cardRecordService.getAllCardRecordByCustomerId(new Page<>(pageNum, pageSize), customerId);
        PageInfo<CardRecordTableVO> page = JsonUtil.pageTransform(recordDTOIPage, CardRecordTableVO.class);
        return RestUtil.success(page);
    }


}

